//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package org.qy137.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qy137.entity.HeadNav;
import org.apache.commons.lang.StringUtils;
import org.qy137.dao.HeadNavDao;
import org.qy137.service.HeadNavService;
import org.qy137.utils.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class HeadNavServiceImpl implements HeadNavService {
    @Autowired
    private HeadNavDao headNavDao;

    public HeadNavServiceImpl() {
    }

    public CommonResult getAllHeadNav(Integer page, Integer limit, HeadNav headNav) {
        Page<HeadNav> navPage = new Page((long)page, (long)limit);
        QueryWrapper<HeadNav> wrapper = new QueryWrapper();
        wrapper.eq("is_delete", 0);
        if (StringUtils.isNotEmpty(headNav.getHeadName())) {
            wrapper.like("head_name", headNav.getHeadName());
        }

        if (StringUtils.isNotEmpty(headNav.getIsDiable())) {
            wrapper.eq("is_diable", headNav.getIsDiable());
        }

        Page<HeadNav> headNavPage = (Page)this.headNavDao.selectPage(navPage, wrapper);
        return headNavPage.getRecords().size() > 0 ? new CommonResult(2000, "查询成功", headNavPage) : new CommonResult(5000, "查询失败", (Object)null);
    }

    public CommonResult deleteHeadNav(Integer headId) {
        HeadNav headNav = new HeadNav();
        headNav.setHeadId(headId);
        headNav.setIsDelete("1");
        int i = this.headNavDao.updateById(headNav);
        return i > 0 ? new CommonResult(2000, "删除成功", (Object)null) : new CommonResult(5000, "删除失败", (Object)null);
    }

    public CommonResult updateDiable(Integer headId, String isDiable) {
        HeadNav headNav = new HeadNav();
        headNav.setHeadId(headId);
        headNav.setIsDiable(isDiable);
        int i = this.headNavDao.updateById(headNav);
        return i > 0 ? new CommonResult(2000, "修改成功", (Object)null) : new CommonResult(5000, "修改失败", (Object)null);
    }

    public CommonResult addHeadNav(HeadNav headNav) {
        HeadNav nav = new HeadNav((Integer)null, headNav.getHeadName(), headNav.getHref(), "0", "0");
        HeadNav nav1 = new HeadNav(headNav.getHeadId(), headNav.getHeadName(), headNav.getHref(), (String)null, (String)null);
        int i;
        if (headNav.getHeadId() == null) {
            i = this.headNavDao.insert(nav);
            return i > 0 ? new CommonResult(2000, "添加成功", (Object)null) : new CommonResult(5000, "添加失败", (Object)null);
        } else {
            i = this.headNavDao.updateById(nav1);
            return i > 0 ? new CommonResult(2000, "修改成功", (Object)null) : new CommonResult(5000, "修改失败", (Object)null);
        }
    }
}
